var formdata;
define(function(require, exports, module){
	var ajax = require("resource/js/component/ajax.js");
	var EUtil = require("resource/js/component/easyutil.js");
	var dgutil,datagridconfig;

	module.exports={
		init:function(){
			$(".pull .tab").click(function(){
				$(this).addClass("tab-select").siblings().removeClass("tab-select");
			});
			$(".pull-left").click(function(){
				var center = $("body").layout().layout("panel","center");
				center.panel("refresh","formadd");
			});
			
			var buttons ={ 
					title:{
						_class:"",
						text:"我的表单"
					},
					btn:[
					     {
					    	 iconCls: 'icon-search',
					    	 url:'/oa/act/approval/form/queryFormByPage.htm',
					    	 text:"查询",
					    	 addClass:'l-btn-display',
					    	 handler: function(){dgutil.pager(1);}
					     },
					     {
					    	 iconCls: 'icon-add',
					    	 addClass:'l-btn-display',
					    	 text:"添加",
					    	 url:'/view/oa/act/approval/form/formadd',
					    	 handler:  function(){
								var center = $("body").layout().layout("panel","center");
								formdata={};
								submitaddress = BASEPATH+"/oa/act/approval/form/saveForm.htm";
								encrypt = true; 
								center.panel("refresh",BASEPATH+"/view/oa/act/approval/form/formedit");
					    	 }
					     },
					     {
					    	 iconCls: 'icon-edit',
					    	 url:'/view/oa/act/approval/form/formedit',
					    	 text:"修改",
					    	 addClass:'l-btn-display',
					    	 needRow:true,
					    	 handler: function(baseUrl,row){
								var center = $("body").layout().layout("panel","center");
								ajax.init().success(function(c,m,d){
									formdata = {form_id:row.form_id,form_name:row.form_name,form_des:row.form_des,cols:d};
									submitaddress = BASEPATH+"/oa/act/approval/form/updateForm.htm";
									encrypt = false; 
									center.panel("refresh",baseUrl);
								}).post(BASEPATH+"/oa/act/approval/form/queryFormCols.htm?form_id="+row.form_id);
					    	 }
					     },
					     {
					    	 iconCls: 'icon-remove',
					    	 url:'/oa/act/approval/form/deleteForm.htm',
					    	 text:"删除",
					    	 addClass:'l-btn-display',
					    	 needRow:true,
					    	 handler: function(baseUrl,rows){
					    		 $.messager.confirm('确认','您确认想要删除表单吗？',function(r){
							    		if(r){
							    			ajax.init().success(function(c,m,d){
								    			using("messager",function(){
								    				$.messager.show('系统提示',m);
								    				dgutil.pager();
								    			})
											}).post(baseUrl+"?form_id="+rows.form_id);
							    		}
						    		 });
						    	 }
					     }
					     ]};
			datagridconfig = {
					toolbar:buttons,
					columns:[[
						         {field:'form_id',title:'表单ID',width:100,align:'center',height:50,hidden:true},
						         {field:'form_name',title:'表单名称',width:100,align:'center',height:50},
						         {field:'form_des',title:'表单描述',width:100,align:'center',height:50},
						         {field:'user_name',title:'创建人',width:50,align:'center',height:50},
						         {field:'user_id',title:'可用状态',width:30,align:'center',height:50,hidden:true},
						         {field:'createtime',title:'创建时间',width:100,align:'center',height:50},
						         {field:'isuse',title:'使用中',width:30,align:'center',height:50,formatter:function(value){
						        	 return value==0?'是':'否'
						         }}
						    ]],
					eid:"formviewdatagrid",
					createPage:true,
					singleSelect:true,
					url:BASEPATH+'/oa/act/approval/form/queryFormByPage.htm',
					args:"searchform"
			};
			using("datagrid",function(){
				dgutil = new EUtil.ajaxDataGrid(datagridconfig);
			});
		}
	}
});